package com.iocup.keybastion.context;

/**
 * 本地线程实现
 *
 * @author xyjxust
 * @create 2022/2/28 16:02
 **/
public class ThreadLocalSecurityContextHandler implements SecurityContextHandler {

    private static final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal();

    @Override
    public void clear() {
        contextHolder.remove();
    }

    @Override
    public SecurityContext get() {
        return contextHolder.get();
    }

    @Override
    public void set(SecurityContext securityContext) {
        if (securityContext == null) {
            throw new SecurityException("securityContext不能为空");
        }
        contextHolder.set(securityContext);
    }
}
